using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Boxes Data Object Class
  /// </summary>
  public partial class DOBoxes
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Boxes BoxNo
		/// </summary>
		public const string RowBoxNo = "BoxNo";

		/// <summary>
		/// The Table Column for the Boxes BoxStatus
		/// </summary>
		public const string RowBoxStatus = "BoxStatus";

		/// <summary>
		/// The Table Column for the Boxes BoxLocation
		/// </summary>
		public const string RowBoxLocation = "BoxLocation";

		/// <summary>
		/// The Table Column for the Boxes BoxWarehouse
		/// </summary>
		public const string RowBoxWarehouse = "BoxWarehouse";

		/// <summary>
		/// The Table Column for the Boxes LastTransactionUserId
		/// </summary>
		public const string RowLastTransactionUserId = "LastTransactionUser_ID";

		/// <summary>
		/// The Table Column for the Boxes LastTransactionDate
		/// </summary>
		public const string RowLastTransactionDate = "LastTransactionDate";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spBoxes_Create";
private const string m_StoredProcedureConstDelete = "spBoxes_Delete";
private const string m_StoredProcedureConstRetrieve = "spBoxes_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spBoxes_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spBoxes_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_BoxNo;
		private string m_BoxStatus;
		private string m_BoxLocation;
		private string m_BoxWarehouse;
		private long m_LastTransactionUserId;
		private DateTime m_LastTransactionDate;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOBoxes> m_Boxess = new List<DOBoxes>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOBoxes() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// BoxNo
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes BoxNo
		/// </remarks>
		public string BoxNo
		{
			get { return (this.m_BoxNo); }
			set { this.m_BoxNo = value; }
		}

		/// <summary>
		/// BoxStatus
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes BoxStatus
		/// </remarks>
		public string BoxStatus
		{
			get { return (this.m_BoxStatus); }
			set { this.m_BoxStatus = value; }
		}

		/// <summary>
		/// BoxLocation
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes BoxLocation
		/// </remarks>
		public string BoxLocation
		{
			get { return (this.m_BoxLocation); }
			set { this.m_BoxLocation = value; }
		}

		/// <summary>
		/// BoxWarehouse
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes BoxWarehouse
		/// </remarks>
		public string BoxWarehouse
		{
			get { return (this.m_BoxWarehouse); }
			set { this.m_BoxWarehouse = value; }
		}

		/// <summary>
		/// LastTransactionUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes LastTransactionUserId
		/// </remarks>
		public long LastTransactionUserId
		{
			get { return (this.m_LastTransactionUserId); }
			set { this.m_LastTransactionUserId = value; }
		}

		/// <summary>
		/// LastTransactionDate
		/// </summary>
		/// <remarks>
		/// This property contains the Boxes LastTransactionDate
		/// </remarks>
		public DateTime LastTransactionDate
		{
			get { return (this.m_LastTransactionDate); }
			set { this.m_LastTransactionDate = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOBoxes> Boxess
	{
	  get { return m_Boxess; }
	  set { m_Boxess = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowBoxNo + "=" + this.BoxNo);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowBoxNo].ToString() != "")
			this.BoxNo = dr[RowBoxNo].ToString();

		if (dr[RowBoxStatus].ToString() != "")
			this.BoxStatus = dr[RowBoxStatus].ToString();

		if (dr[RowBoxLocation].ToString() != "")
			this.BoxLocation = dr[RowBoxLocation].ToString();

		if (dr[RowBoxWarehouse].ToString() != "")
			this.BoxWarehouse = dr[RowBoxWarehouse].ToString();

		if (dr[RowLastTransactionUserId].ToString() != "")
			this.LastTransactionUserId = long.Parse(dr[RowLastTransactionUserId].ToString());

		if (dr[RowLastTransactionDate].ToString() != "")
			this.LastTransactionDate = DateTime.Parse(dr[RowLastTransactionDate].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOBoxes Boxes = new DOBoxes();
			
					if (dr[RowBoxNo].ToString() != "")
			Boxes.BoxNo = dr[RowBoxNo].ToString();

		if (dr[RowBoxStatus].ToString() != "")
			Boxes.BoxStatus = dr[RowBoxStatus].ToString();

		if (dr[RowBoxLocation].ToString() != "")
			Boxes.BoxLocation = dr[RowBoxLocation].ToString();

		if (dr[RowBoxWarehouse].ToString() != "")
			Boxes.BoxWarehouse = dr[RowBoxWarehouse].ToString();

		if (dr[RowLastTransactionUserId].ToString() != "")
			Boxes.LastTransactionUserId = long.Parse(dr[RowLastTransactionUserId].ToString());

		if (dr[RowLastTransactionDate].ToString() != "")
			Boxes.LastTransactionDate = DateTime.Parse(dr[RowLastTransactionDate].ToString());

            this.Boxess.Add(Boxes);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
